<?php

namespace App\Http\Requests\ShopAddressController;

use Illuminate\Foundation\Http\FormRequest;

class ShopAddressStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|string',
            'phone' => 'required|string|regex:/^1[2345789][0-9]{9}$/',
            'province' => 'required|string',
            'city' => 'required|string',
            'area' => 'required|string',
            'detailed_address' => 'required|string',
            'postal_code' => 'nullable|string',
        ];
    }

    public function messages()
    {
        return [
            'name.required' => __('姓名不能为空'),
            'name.string' => __('姓名必须是字符串类型'),
            'phone.required' => __('手机号不能为空'),
            'phone.string' => __('手机号必须是字符串类型'),
            'phone.regex' => __('手机号格式错误'),
            'province.required' => __('省不能为空'),
            'province.string' => __('省必须是字符串类型'),
            'city.required' => __('市不能为空'),
            'city.string' => __('市必须是字符串类型'),
            'area.required' => __('区不能为空'),
            'area.string' => __('区必须是字符串类型'),
            'detailed_address.required' => __('详细地址不能为空'),
            'detailed_address.string' => __('详细地址必须是字符串类型'),
            'postal_code.string' => __('邮政编码必须是字符串类型'),
        ];
    }
}
